import BaseChannel from "../../base/BaseChannel";
import RandomHelper from "../../../cfw/tools/RandomHelper";
import GameItemModel from "../../base/GameItemModel";
import BaseView from "../../../cfw/mvc/BaseView";
import SDKManager from "../../SDKManager";


let NAMES: string[] = ['张天培', '马明宇', '姚启胜', '孙忠祥', '吴绮丽']

const { ccclass, property } = cc._decorator;

@ccclass
export default class FriendView extends BaseView {

	@property({ type: cc.Sprite, displayName: "tipNode$VSprite" })
	tipNode$VSprite: cc.Sprite = null;

	@property({ type: cc.Button, displayName: "tipNode$VButton" })
	tipNode$VButton: cc.Button = null;

	@property({ type: cc.Label, displayName: "name$VLabel" })
	name$VLabel: cc.Label = null;

	@property({ type: cc.Label, displayName: "who$VLabel" })
	who$VLabel: cc.Label = null;
	protected model: BaseChannel;
	protected item: GameItemModel;
	protected isClick: number = 0;
	protected duration: number = 30000;
	onLoad() {
		this.setTimeout(() => {
			this.startShow();
		}, this.duration)

	}


	startShow() {
		let list = this.model.getAdData()
		this.item = list[RandomHelper.random(0, list.length)]
		if (this.item) {
			let name = NAMES[RandomHelper.random(0, NAMES.length)]
			this.who$VLabel.string = name;
			this.name$VLabel.string = this.item.getGameName()
			cc.tween(this.tipNode$VButton.node).by(0.3, { y: -this.tipNode$VButton.node.height }).start()
			this.isClick = 1;
			this.setTimeout(() => {
				if (this.isClick == 1) {
					this.back();
				}
			}, 3000)
			this.setTimeout(() => {
				this.startShow();
			}, this.duration)
		}
	}



	back() {
		cc.tween(this.tipNode$VButton.node).by(0.5, { y: this.tipNode$VButton.node.height }).start()
	}




	ontipNode$VButtonClick() {
		if (this.item) {
			this.isClick = 2;
			this.back()

			SDKManager.getChannel().toOtherGame(this.item)
		}

	}



}